{include file="public/head"}
<div class="main">
    {include file="public/left"}
    <div class="middle">
    {include file="public/header"}
    <div class='userinfo'>
        {include file="public/userleft"}
        <div class="pub_task">
            <h5>{:__('我参加的悬赏任务')}</h5>
            <ul class="layui-tab-title">
                <li data-target="0" class="layui-this">{:__('全部')}</li>
            </ul>
            <ul class="task_table">
                <dl><span>{:__('任务编号')}</span><span>{:__('任务标题')}</span><span>{:__('任务金额')}</span><span>{:__('发布时间')}</span><span>{:__('状态')}</span><span>{:__('操作')}</span></dl>
            </ul>
        </div>
    </div>
    <div id="in_page" style="margin-left: 23%;"></div>
    {include file="public/foot"}
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<script>
    var status = '';
    noLog();
    $(document).queue('task',function(){
        $.ajax({
            url:'/api/mission/getOptions',
            type:'post',
            data:{params:'mission_status'},
            success:function(ret){
                var htl='';
                if(ret.code == 1){
                    for(i in ret['data']['mission_status']){
                        if(i == 1 || i == 2){
                            continue;
                        }
                        htl+='<li data-target="'+i+'">'+ret['data']['mission_status'][i]+'</li>';
                    }
                    $(".pub_task .layui-tab-title").append(htl);
                    $(document).dequeue('task');
                } else if(ret.code != 401){
                    layer.msg(ret.msg,{icon:2});
                }
            }
        });
    });

    var total = 0;
    function gettask(newpage,status)
    {
        $.ajax({
            url:'/api/mission/myInvolved',
            type:'get',
            data:{'token':token,'page':newpage,'limit':5,status:status},
            success:function(ret){
                if(ret.code == 1){
                    $("._list").remove();
                    if(ret['data'] == '' && ret['data'] == null && ret['data'] == undefined){
                        return fasle;
                    }
                    if(ret['data']['ls'] == '' && ret['data']['ls'] == null && ret['data']['ls'] == undefined){
                        return fasle;
                    }
                    var htl = "";
                    for(i in ret['data']['ls']){
                        var status = "";
                        var option = "";
                        if(ret['data']['ls'][i]['status'] == 1){
                            status = '{:__("待付款")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a><a class="_edit" data-target="'+ret['data']['ls'][i]['mission_id']+'">{:__("编辑")}</a><a data-target="'+ret['data']['ls'][i]['mission_id']+'" class="_pay">{:__("付款")}</a><a class="_del">{:__("删除")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 2){
                            status = '{:__("待审核")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 3){
                            status = '{:__("进行中")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        } else if(ret['data']['ls'][i]['status'] == 4){
                            status = '{:__("完成")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                            if(ret['data']['ls'][i]['dissent'] == '' || ret['data']['ls'][i]['dissent'] == null || ret['data']['ls'][i]['dissent'] == undefined){
                                option += '<a class="arbitration" data-target="'+ret['data']['ls'][i]['mission_id']+'">{:__("申请仲裁")}</a>';
                            } else {
                                option += '<a>{:__("已仲裁")}</a>';
                            }
                        } else if(ret['data']['ls'][i]['status'] == 5){
                            status = '{:__("仲裁中")}';
                            option = '<a class="lookdetail" data-target="'+ret['data']['ls'][i]['route']+'">{:__("查看")}</a>';
                        }
                        if(ret['data']['ls'][i]['mission_no'] == '' || ret['data']['ls'][i]['mission_no'] =='' || ret['data']['ls'][i]['mission_no'] == undefined){
                            ret['data']['ls'][i]['mission_no'] = '';
                        }
                        if(ret['data']['ls'][i]['title'] == '' || ret['data']['ls'][i]['title'] == '' || ret['data']['ls'][i]['title'] == undefined){
                            ret['data']['ls'][i]['title'] = '';
                        }
                        htl += '<dl class="_list">'
                            +'<span>'+ret['data']['ls'][i]['mission_no']+'</span>'
                            +'<span>'+ret['data']['ls'][i]['title']+'</span>'
                            +'<span>'+ret['data']['ls'][i]['money']+'</span>'
                            +'<span>'+ret['data']['ls'][i]['create_time']+'</span>'
                            +'<span>'+status+'</span>'
                            +'<span>'+option+'</span>'
                            +'</dl>';
                    }
                    $(".task_table").append(htl);
                    total = ret['data']['total'];
                    if(newpage == 1){
                        pagechange();
                    }
                   
                } else if(ret.code != 401){
                    layer.msg(ret.msg,{icon:2});
                }
            }
        });
    }
    $(document).on("click",".lookdetail",function(){
        var _this = $(this);
        var url = _this.attr("data-target");
        window.location.href="/"+url;
    });
    function pagechange()
    {
        //分页
        createpage('in_page',total,5,function(obj,first){
            var nowpage = obj.curr;
            if(!first){
                gettask(nowpage,status);
            }
        });
    }
    $(document).queue('task',function(){
        gettask(1,status);
    });
    $(document).dequeue('task');
    $(document).on("click",'.pub_task .layui-tab-title li',function(){
        var _this = $(this);
        status = _this.attr("data-target");
        gettask(1,status);
    });
    $(document).on("click",".arbitration",function(){
        var mission_id = $(this).attr("data-target");
        layer.confirm("{:__('是否确认申请仲裁')}",{title:"{:__('提示')}",btn:['{:__("确定")}','{:__("取消")}']},function(){
            $.ajax({
                url:"/api/mission/arbitration",
                type:'post',
                data:{token:token,mission_id:mission_id},
                success:function(ret){
                    if(ret['code'] == 1){
                        layer.msg(ret['msg'],{icon:1});
                    } else if(ret['code'] != 401){
                        layer.msg(ret['msg'],{icon:2});
                    }
                }
            });
        });
        
    });
</script>